<?php

//require_once dirname(__DIR__)."/login_filter.php";
require_once dirname(dirname(__DIR__))."/common.php";
use app\cls\tom\FFmpeg;
use app\cls\tom\Response;
use app\cls\tom\SysResource;
use app\cls\tom\Tools;
use app\cls\tom\Config;

$video=$_REQUEST['video_url'];
$ffmpeg=new FFmpeg();
$img_path=upload_dir();
$re=$ffmpeg->getCoverFromVideo1($video,$img_path['savepath']);
//var_dump($re);exit;
if($re){
    Response::output(0,"截图成功",$img_path);
}else{
    Response::output(-1,"截图失败",$ffmpeg->getLastError());
}
function getMsecTime()
{
    list($msec, $sec) = explode(' ', microtime());
    $msectime =  (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
    return $msectime;
}
function upload_dir($type="tmp",$suffix="jpg"){
    //解决跨域问题
    $allUploadConfig = Config::load("cos_upload");
    $uploadConfig = $allUploadConfig[$type];
    //创建上传目录，配置上传
    $date1=date("Y",time());
    $date2=date("m",time());
    $date3=date("d",time());
    $dir="/".$date1."/".$date2."/".$date3;
    $uploadpath1=$uploadConfig['savepath'];
    $uploadpath2=$uploadConfig['savehttp'];
    $key1=rand(1000,10000);
    $key2=rand(10000,20000);
    $key3=rand();
    $file_name=$key1.$key2.$key3;
    //这是服务器上的上传地址
    $uploadpath['savepath']=$uploadpath1.$dir."/".$file_name.".{$suffix}";
    if($type=="video"){
        mkdir($uploadpath1.$dir."/".$file_name,0777,true);
    }
    //这是网络访问地址
    $uploadpath['savehttp']=$uploadpath2.$dir."/".$file_name.".{$suffix}";
    return $uploadpath;
}
